function addCategory() {
    Ajax.getHtml('category/categoryAdd.html', function (html) {
        layer.open({
            type: 1,
            title: '新增产品类型',
            area: ['600px'],
            content: html,
            btn: ['确认', '取消'],
            yes: function () {
                saveCategory()
            },
            btn2: function () {
                console.log('取消新增产品类型')
            }
        })
    })
}

function saveCategory() {
    Ajax.post(
        '/addCategory',
        {
            name:$("#categoryName").val(),
            remark:$("#remark").val()
        },
        function (result) {
            doResult(result, function () {
                layer.closeAll()
                show('category/category.html')
                layer.alert(result.msg)
            })
        }
    )
}
function updateCategory() {
    Ajax.post(
        '/updateCategory',
        {
            categoryID:$("#categoryID").val(),
            name:$("#categoryName").val(),
            remark:$("#remark").val()
        },
        function (result) {
            doResult(result, function () {
                layer.closeAll()
                show('category/category.html')
                layer.alert(result.msg)
            })
        }
    )
}
function addProduct() {
    Ajax.getHtml('category/productAdd.html', function (html) {
        layer.open({
            type: 1,
            title: '新增产品',
            area: ['600px'],
            content: html,
            btn: ['确认', '取消'],
            yes: function () {
                saveProduct()
            },
            btn2: function () {
                console.log('取消新增产品')
            }
        })
    })
}
function saveProduct() {
    Ajax.post(
        '/addProduct',
        {
            productCode:$("#productCode").val(),
            categoryId:$('input[type=radio]:checked').val(),
            name:$("#productName").val(),
            unitName:$("#unitName").val(),
            price:$("#price").val(),
            createDate:$("#price").val(),
            remark:$("#remark").val(),
            num:$("#num").val(),
            poNum:$("#poNum").val(),
            soNum:$("#soNum").val()
        },
        function (result) {
            doResult(result, function () {
                layer.closeAll()
                show('category/product.html')
                layer.alert(result.msg)
            })
        }
    )
}
function updateproduct() {
    Ajax.post(
        '/updateProduct',
        {
            productCode:$("#productCode").val(),
            categoryId:$('input[type=radio]:checked').val(),
            name:$("#productName").val(),
            unitName:$("#unitName").val(),
            price:$("#price").val(),
            createDate:$("#price").val(),
            remark:$("#remark").val(),
            num:$("#num").val(),
            poNum:$("#poNum").val(),
            soNum:$("#soNum").val()
        },
        function (result) {
            doResult(result, function () {
                layer.closeAll()
                show('category/product.html')
                layer.alert(result.msg)
            })
        }
    )
}
